package com.hnl.test;

import java.text.ParseException;
import java.util.Date;
import java.util.Vector;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hnl.dao.ActivityDAO;
import com.hnl.dao.DAOException;
import com.hnl.dao.FunctionDAO;
import com.hnl.dao.HNLDAOFactory;
import com.hnl.dao.MiscDAO;
import com.hnl.dao.MiscTypeDAO;
import com.hnl.dao.RoleDAO;
import com.hnl.dao.RoleFunctionDAO;
import com.hnl.dao.TalentDAO;
import com.hnl.dao.TalentEducationDAO;
import com.hnl.dao.UserDAO;
import com.hnl.to.Activity;
import com.hnl.to.Function;
import com.hnl.to.Misc;
import com.hnl.to.MiscType;
import com.hnl.to.Role;
import com.hnl.to.RoleFunction;
import com.hnl.to.Talent;
import com.hnl.to.TalentEducation;
import com.hnl.to.User;
import com.hnl.util.FormatUtil;

public class GenerateTestData {
	public static final Logger LOG = LoggerFactory
			.getLogger(GenerateTestData.class);

	public static void main() {
		testMisc();
		testUserAndRoles();
		// testTalent();
		// testEducation();
		// testActivity();
	}

	private static void testMisc() {

		try {
			MiscTypeDAO miscTypeDAO = HNLDAOFactory.getDAOFactory(
					HNLDAOFactory.HNLDAOFACTORY).getMiscTypeDAO();
			MiscDAO miscDAO = HNLDAOFactory.getDAOFactory(
					HNLDAOFactory.HNLDAOFACTORY).getMiscDAO();

			Date now = new Date();

			MiscType miscType = new MiscType();
			miscType.setTypeName("DEFAULT");
			miscType.setTypeDesc("Default");
			miscType.setModifyDate(now);
			miscType.setModifyUser(1);
			miscType.setCreateDate(now);
			miscType.setCreateUser(1);
			miscTypeDAO.saveMiscType(miscType);

			Misc misc = new Misc();
			String[] options = { "N/A" };
			int num = options.length;
			for (int i = 0; i < num; i++) {
				misc.setMiscName(options[i]);
				misc.setMiscDesc(options[i]);
				misc.setMiscTypeID(miscType.getMiscTypeID());
				misc.setModifyDate(now);
				misc.setModifyUser(1);
				misc.setCreateDate(now);
				misc.setCreateUser(1);
				miscDAO.saveMisc(misc);
			}

			miscType = new MiscType();
			miscType.setTypeName("GENDER");
			miscType.setTypeDesc("Gender");
			miscType.setModifyDate(now);
			miscType.setModifyUser(1);
			miscType.setCreateDate(now);
			miscType.setCreateUser(1);
			miscTypeDAO.saveMiscType(miscType);

			misc = new Misc();
			options = new String[] { "Male", "Female" };
			num = options.length;
			for (int i = 0; i < num; i++) {
				misc.setMiscName(options[i]);
				misc.setMiscDesc(options[i]);
				misc.setMiscTypeID(miscType.getMiscTypeID());
				misc.setModifyDate(now);
				misc.setModifyUser(1);
				misc.setCreateDate(now);
				misc.setCreateUser(1);
				miscDAO.saveMisc(misc);
			}

			miscType = new MiscType();
			miscType.setTypeName("USER_ROLES");
			miscType.setTypeDesc("User Roles");
			miscType.setModifyDate(now);
			miscType.setModifyUser(1);
			miscType.setCreateDate(now);
			miscType.setCreateUser(1);
			miscTypeDAO.saveMiscType(miscType);

			misc = new Misc();
			options = new String[] { "Administrator", "Consultant" };
			num = options.length;
			for (int i = 0; i < num; i++) {
				misc.setMiscName(options[i]);
				misc.setMiscDesc(options[i]);
				misc.setMiscTypeID(miscType.getMiscTypeID());
				misc.setModifyDate(now);
				misc.setModifyUser(1);
				misc.setCreateDate(now);
				misc.setCreateUser(1);
				miscDAO.saveMisc(misc);
			}

			miscType = new MiscType();
			miscType.setTypeName("USER_FUNCTIONS");
			miscType.setTypeDesc("User Functions");
			miscType.setModifyDate(now);
			miscType.setModifyUser(1);
			miscType.setCreateDate(now);
			miscType.setCreateUser(1);
			miscTypeDAO.saveMiscType(miscType);

			misc = new Misc();
			options = new String[] { "AddTalentAccess", "DeleteTalentAccess",
					"UserManagementAccess" };
			num = options.length;
			for (int i = 0; i < num; i++) {
				misc.setMiscName(options[i]);
				misc.setMiscDesc(options[i]);
				misc.setMiscTypeID(miscType.getMiscTypeID());
				misc.setModifyDate(now);
				misc.setModifyUser(1);
				misc.setCreateDate(now);
				misc.setCreateUser(1);
				miscDAO.saveMisc(misc);
			}

			miscType = new MiscType();
			miscType.setTypeName("NATIONALITY");
			miscType.setTypeDesc("nationality");
			miscType.setModifyDate(now);
			miscType.setModifyUser(1);
			miscType.setCreateDate(now);
			miscType.setCreateUser(1);
			miscTypeDAO.saveMiscType(miscType);

			options = new String[] { "Taiwan", "China",
					"United States of America", "Australia", "Belgium",
					"Brazil", "Canada", "Czech Republic", "Denmark", "Egypt",
					"France", "Germany", "Germany", "Great Britain", "Greece",
					"India", "Indonesia", "Ireland", "Israel", "Italy",
					"Japan", "Malaysia", "Mexico", "Mongolia", "New Zealand",
					"Philippines", "Poland", "Portugal", "Russia", "Singapore",
					"South Africa", "South Korea", "Spain", "Sweden",
					"Switzerland", "Thai", "Turkey", "Ukraine", "Vietnam",
					"Other" };
			num = options.length;
			for (int i = 0; i < num; i++) {
				misc.setMiscName(options[i]);
				misc.setMiscDesc(options[i]);
				misc.setMiscTypeID(miscType.getMiscTypeID());
				misc.setModifyDate(now);
				misc.setModifyUser(1);
				misc.setCreateDate(now);
				misc.setCreateUser(1);
				miscDAO.saveMisc(misc);
			}

			miscType = new MiscType();
			miscType.setTypeName("RELIGION");
			miscType.setTypeDesc("religion");
			miscType.setModifyDate(now);
			miscType.setModifyUser(1);
			miscType.setCreateDate(now);
			miscType.setCreateUser(1);
			miscTypeDAO.saveMiscType(miscType);

			misc = new Misc();
			options = new String[] { "Buddhism",
					"Chinese Traditional Religion", "Christianity", "Islam",
					"Spiritism", "Other" };
			num = options.length;
			for (int i = 0; i < num; i++) {
				misc.setMiscName(options[i]);
				misc.setMiscDesc(options[i]);
				misc.setMiscTypeID(miscType.getMiscTypeID());
				misc.setModifyDate(now);
				misc.setModifyUser(1);
				misc.setCreateDate(now);
				misc.setCreateUser(1);
				miscDAO.saveMisc(misc);
			}

			miscType = new MiscType();
			miscType.setTypeName("CURRENT_COUNTRY");
			miscType.setTypeDesc("current_country");
			miscType.setModifyDate(now);
			miscType.setModifyUser(1);
			miscType.setCreateDate(now);
			miscType.setCreateUser(1);
			miscTypeDAO.saveMiscType(miscType);

			misc = new Misc();
			options = new String[] { "Taiwan", "China",
					"United States of America", "Australia", "Belgium",
					"Brazil", "Canada", "Czech Republic", "Denmark", "Egypt",
					"France", "Germany", "Germany", "Great Britain", "Greece",
					"India", "Indonesia", "Ireland", "Israel", "Italy",
					"Japan", "Malaysia", "Mexico", "Mongolia", "New Zealand",
					"Philippines", "Poland", "Portugal", "Russia", "Singapore",
					"South Africa", "South Korea", "Spain", "Sweden",
					"Switzerland", "Thai", "Turkey", "Ukraine", "Vietnam",
					"Other" };
			num = options.length;
			for (int i = 0; i < num; i++) {
				misc.setMiscName(options[i]);
				misc.setMiscDesc(options[i]);
				misc.setMiscTypeID(miscType.getMiscTypeID());
				misc.setModifyDate(now);
				misc.setModifyUser(1);
				misc.setCreateDate(now);
				misc.setCreateUser(1);
				miscDAO.saveMisc(misc);
			}

			miscType = new MiscType();
			miscType.setTypeName("INDUSTRY_LEVEL_1");
			miscType.setTypeDesc("industry_level_1");
			miscType.setModifyDate(now);
			miscType.setModifyUser(1);
			miscType.setCreateDate(now);
			miscType.setCreateUser(1);
			miscTypeDAO.saveMiscType(miscType);

			misc = new Misc();
			options = new String[] {
					"Computer and Consumer Electronics Manufacturing",
					"Electronic / Semiconductor Industry",
					"Electronic Components related",
					"Financial Investment related", "Healthcare related",
					"Legal / Accounting / HR", "Optical and Optical related",
					"Software and Internet-related",
					"Telecommunications related",
					"Transportation Logistics and Warehousing", "Other" };
			num = options.length;
			for (int i = 0; i < num; i++) {
				misc.setMiscName(options[i]);
				misc.setMiscDesc(options[i]);
				misc.setMiscTypeID(miscType.getMiscTypeID());
				misc.setModifyDate(now);
				misc.setModifyUser(1);
				misc.setCreateDate(now);
				misc.setCreateUser(1);
				miscDAO.saveMisc(misc);
			}

			miscType = new MiscType();
			miscType.setTypeName("INDUSTRY_LEVEL_2");
			miscType.setTypeDesc("industry_level_2");
			miscType.setModifyDate(now);
			miscType.setModifyUser(1);
			miscType.setCreateDate(now);
			miscType.setCreateUser(1);
			miscTypeDAO.saveMiscType(miscType);

			misc = new Misc();
			options = new String[] { "Other" };
			num = options.length;
			for (int i = 0; i < num; i++) {
				misc.setMiscName(options[i]);
				misc.setMiscDesc(options[i]);
				misc.setMiscTypeID(miscType.getMiscTypeID());
				misc.setModifyDate(now);
				misc.setModifyUser(1);
				misc.setCreateDate(now);
				misc.setCreateUser(1);
				miscDAO.saveMisc(misc);
			}

			miscType = new MiscType();
			miscType.setTypeName("MARITAL_STATUS");
			miscType.setTypeDesc("marital_status");
			miscType.setModifyDate(now);
			miscType.setModifyUser(1);
			miscType.setCreateDate(now);
			miscType.setCreateUser(1);
			miscTypeDAO.saveMiscType(miscType);

			misc = new Misc();
			options = new String[] { "Single", "Married" };
			num = options.length;
			for (int i = 0; i < num; i++) {
				misc.setMiscName(options[i]);
				misc.setMiscDesc(options[i]);
				misc.setMiscTypeID(miscType.getMiscTypeID());
				misc.setModifyDate(now);
				misc.setModifyUser(1);
				misc.setCreateDate(now);
				misc.setCreateUser(1);
				miscDAO.saveMisc(misc);
			}

			miscType = new MiscType();
			miscType.setTypeName("ACTIVITY_TYPE");
			miscType.setTypeDesc("activity_type");
			miscType.setModifyDate(now);
			miscType.setModifyUser(1);
			miscType.setCreateDate(now);
			miscType.setCreateUser(1);
			miscTypeDAO.saveMiscType(miscType);

			misc = new Misc();
			options = new String[] { "Phone screen",
					"Face to Face interview", "Follow-up interview",
					"Follow-up calls", "Shortlisted", "Blacklisted",
					"Client Interview In Progress", "Client rejected",
					"Client Offered", "Candidate rejected the offer",
					"Successful placed", "Failed within probation period" };
			num = options.length;
			for (int i = 0; i < num; i++) {
				misc.setMiscName(options[i]);
				misc.setMiscDesc(options[i]);
				misc.setMiscTypeID(miscType.getMiscTypeID());
				misc.setModifyDate(now);
				misc.setModifyUser(3);
				misc.setCreateDate(now);
				misc.setCreateUser(3);
				miscDAO.saveMisc(misc);
			}

			miscType = new MiscType();
			miscType.setTypeName("ATTACHMENT_TYPE");
			miscType.setTypeDesc("attachment_type");
			miscType.setModifyDate(now);
			miscType.setModifyUser(1);
			miscType.setCreateDate(now);
			miscType.setCreateUser(1);
			miscTypeDAO.saveMiscType(miscType);

			misc = new Misc();
			options = new String[] { "Original", "Shortlist", "ReferenceReport" };
			num = options.length;
			for (int i = 0; i < num; i++) {
				misc.setMiscName(options[i]);
				misc.setMiscDesc(options[i]);
				misc.setMiscTypeID(miscType.getMiscTypeID());
				misc.setModifyDate(now);
				misc.setModifyUser(3);
				misc.setCreateDate(now);
				misc.setCreateUser(3);
				miscDAO.saveMisc(misc);
			}

		} catch (DAOException e) {
			LOG.error("Error in Getting DAO. ", e);
		}

	}

	@Deprecated
	private static void testTalent() {
		try {
			TalentDAO talentDAO = HNLDAOFactory.getDAOFactory(
					HNLDAOFactory.HNLDAOFACTORY).getTalentDAO();

			Date now = new Date();

			// test add talent
			Talent talent = new Talent();
			talent.setBirthdate(FormatUtil.getDateFormatUS()
					.parse("08-09-1979"));
			talent.setCareerGoal("test career goal");
			talent.setCell1("0910-272-255");
			talent.setCell2("0910-272-255");
			talent.setcFirstname("Hui Lan");
			talent.setCity("Taipe");
			talent.setcLastname("Chi");
			talent.setComMail("huilan@nmi.iii.org.tw");
			talent.setComment("test comment");
			talent.setCompany("III");
			talent.setCountry(22);
			talent.setCreateDate(now);
			talent.setCreateUser(3);
			talent.setDid("0910-272-255");
			talent.seteFirstname("Parkin");
			talent.seteLastname("Chi");
			talent.setExpertise("1.Expertise one.\n2.Expetise two.");
			talent.setFacebook("parkinchi@msn.com");
			talent.setFamilyBackground("1.Family background one.\n2.Family background two.");
			talent.setHomePhone("26826916");
			talent.setIndustry1(289);
			talent.setIndustry2(416);
			talent.setInterest("1.Interest one.\n2.Interest two.");
			talent.setIsdelete(false);
			talent.setJobfunction("1.Job function one.\n2.Job function two.");
			talent.setLanguageSkill("English, Japanese");
			talent.setLinkedin("parkinchi@hotmail.com");
			talent.setModifyDate(now);
			talent.setModifyUser(3);
			talent.setRating("jeffreychang@hotmail.com");
			talent.setNationality(8);
			talent.setOfficeTel("66073727");
			talent.setPersonalMail("parkinchi@hotmail.com");
			talent.setPosition("Manager");
			talent.setReligion(14);
			talent.setSalary("10000");
			talent.setSkype("parkinchi@hotmail.com");
			talent.setOthers("1.Social Connection one.\n2.Social Connection two.");
			talent.setTotalYearsOfWork("10");
			talent.setWorkExperience("1.Work exp one.\n2.Work exp two.");
			talent.setMaritalStatus(417);
			talent.setGender(1);
			talentDAO.saveTalent(talent);

			talent.setBirthdate(FormatUtil.getDateFormatUS()
					.parse("08-09-1979"));
			talent.setCareerGoal("I want to be an executive who can lead million dollar operations");
			talent.setCell1("0910-272-255");
			talent.setCell2("0910-272-255");
			talent.setcFirstname("Jeffrey");
			talent.setCity("Shanghai");
			talent.setcLastname("Chang");
			talent.setComMail("jeffreychang@hotmail.com");
			talent.setComment("I love to play poker");
			talent.setCompany("Trend Micro");
			talent.setCountry(22);
			talent.setCreateDate(now);
			talent.setCreateUser(1);
			talent.setDid("0397-088-148");
			talent.seteFirstname("Jeffrey");
			talent.seteLastname("Chang");
			talent.setExpertise("JAVA, Enterprise Architecture");
			talent.setFacebook("jeffreychang@hotmail.com");
			talent.setFamilyBackground("One brother, mom and dad");
			talent.setHomePhone("28215956");
			talent.setIndustry1(289);
			talent.setIndustry2(416);
			talent.setInterest("Sleeping, coding");
			talent.setIsdelete(false);
			talent.setJobfunction("Responsible for leading and overseeing whole JAVA operation");
			talent.setLanguageSkill("English, Japanese");
			talent.setLinkedin("jeffreychang@hotmail.com");
			talent.setModifyDate(now);
			talent.setModifyUser(1);
			talent.setRating("jeffreychang@hotmail.com");
			talent.setNationality(9);
			talent.setOfficeTel("66073727");
			talent.setPersonalMail("jeffreychang@hotmail.com");
			talent.setPosition("Enterprise Architect");
			talent.setReligion(14);
			talent.setSalary("20000");
			talent.setSkype("jeffreychang@hotmail.com");
			talent.setOthers("1.Social Connection one.\n2.Social Connection two.");
			talent.setTotalYearsOfWork("9");
			talent.setWorkExperience("1.Work exp one.\n2.Work exp two.");
			talent.setMaritalStatus(417);
			talent.setGender(1);
			talentDAO.saveTalent(talent);
		} catch (DAOException e) {
			LOG.error("Error in Getting DAO. ", e);
		} catch (ParseException e) {
			LOG.error("Error in Getting DAO-- Birthdate. ", e);
		}
	}

	private static void testUserAndRoles() {
		try {
			UserDAO userDAO = HNLDAOFactory.getDAOFactory(
					HNLDAOFactory.HNLDAOFACTORY).getUserDAO();
			RoleDAO roleDAO = HNLDAOFactory.getDAOFactory(
					HNLDAOFactory.HNLDAOFACTORY).getRoleDAO();
			FunctionDAO functionDAO = HNLDAOFactory.getDAOFactory(
					HNLDAOFactory.HNLDAOFACTORY).getFunctionDAO();
			RoleFunctionDAO roleFunctionDAO = HNLDAOFactory.getDAOFactory(
					HNLDAOFactory.HNLDAOFACTORY).getRoleFunctionDAO();

			Date now = new Date();
			User newUser = null;
			Role newRole = null;
			Function function = null;
			RoleFunction roleFunction = null;

			function = new Function();
			function.setFunction(6);
			function.setCreateDate(now);
			function.setCreateUserID(1);
			function.setModifyDate(now);
			function.setModifyUserID(1);
			functionDAO.saveRoleFunction(function);
			function.setFunction(7);
			functionDAO.saveRoleFunction(function);
			function.setFunction(8);
			functionDAO.saveRoleFunction(function);

			newRole = new Role();
			newRole.setRoleName(4);
			newRole.setCreateDate(now);
			newRole.setCreateUserID(1);
			newRole.setModifyDate(now);
			newRole.setModifyUserID(1);
			roleDAO.saveRole(newRole);

			roleFunction = new RoleFunction();
			roleFunction.setRoleID(newRole.getRoleID());
			roleFunction.setFunctionID(1);
			roleFunctionDAO.saveRoleFunction(roleFunction);
			roleFunction.setFunctionID(2);
			roleFunctionDAO.saveRoleFunction(roleFunction);
			roleFunction.setFunctionID(3);
			roleFunctionDAO.saveRoleFunction(roleFunction);

			newRole = new Role();
			newRole.setRoleName(5);
			newRole.setCreateDate(now);
			newRole.setCreateUserID(1);
			newRole.setModifyDate(now);
			newRole.setModifyUserID(1);
			roleDAO.saveRole(newRole);

			roleFunction = new RoleFunction();
			roleFunction.setRoleID(newRole.getRoleID());
			roleFunction.setFunctionID(1);
			roleFunctionDAO.saveRoleFunction(roleFunction);

			Vector<String[]> users = new Vector<String[]>();
			users.add(new String[] { "Yinshew", "Liao", "yinshew@gmail.com",
					"1234" });
			users.add(new String[] { "Parkin", "Chi", "parkinchi@gmail.com",
					"1234" });
			users.add(new String[] { "Maggie", "Hsu",
					"maggie_hsu@hnl-consultants.com", "1234" });
			users.add(new String[] { "Samantha", "Lin",
					"samantha_lin@hnl-consultants.com", "1234" });
			users.add(new String[] { "Peggy", "Huang",
					"peggy_huang@hnl-consultants.com", "1234" });
			users.add(new String[] { "Cathy", "Li",
					"cathy_li@hnl-consultants.com", "1234" });
			users.add(new String[] { "Carol", "Liao",
					"carol_liao@hnl-consultants.com", "1234" });
			users.add(new String[] { "Lulu", "Chen",
					"lulu_chen@hnl-consultants.com", "1234" });
			users.add(new String[] { "Wendy", "Hsieh",
					"wendy_hsieh@hnl-consultants.com", "1234" });
			users.add(new String[] { "Candis", "Ko",
					"candis_ko@hnl-consultants.com", "1234" });

			for (String[] user : users) {
				newUser = new User();
				newUser.setFirstname(user[0]);
				newUser.setLastname(user[1]);
				newUser.setEmail(user[2]);
				newUser.setPassword(user[3]);
				newUser.setLastLoginDate(now);
				newUser.setRoleID(1);
				newUser.setIsDelete(false);
				newUser.setCreateDate(now);
				newUser.setCreateUserID(null);
				newUser.setModifyDate(now);
				newUser.setModifyUserID(1);
				userDAO.saveUser(newUser);
			}

			users = new Vector<String[]>();
			users.add(new String[] { "Jeffrey", "Chang", "jclalala@gmail.com",
					"1234" });

			for (String[] user : users) {
				newUser = new User();
				newUser.setFirstname(user[0]);
				newUser.setLastname(user[1]);
				newUser.setEmail(user[2]);
				newUser.setPassword(user[3]);
				newUser.setLastLoginDate(now);
				newUser.setRoleID(2);
				newUser.setIsDelete(false);
				newUser.setCreateDate(now);
				newUser.setCreateUserID(null);
				newUser.setModifyDate(now);
				newUser.setModifyUserID(1);
				userDAO.saveUser(newUser);
			}

		} catch (DAOException e) {
			LOG.error("Error in Getting DAO. ", e);
		}
	}

	private static void testEducation() {
		try {
			TalentEducationDAO talentEduDAO = HNLDAOFactory.getDAOFactory(
					HNLDAOFactory.HNLDAOFACTORY).getTalentEducationDAO();

			TalentEducation talentEdu = new TalentEducation();
			talentEdu.setDegree("M.S.");
			talentEdu.setDuration("2007-2009");
			talentEdu.setIsdelete(false);
			talentEdu.setMajor("Computer Science");
			talentEdu.setSchool("University of Virginia");
			talentEdu.setTalentID(1);

			talentEduDAO.saveTalentEducation(talentEdu);
		} catch (DAOException e) {
			LOG.error("Error in Getting DAO. ", e);
		}
	}

	@Deprecated
	private static void testActivity() {
		try {
			ActivityDAO activityDAO = HNLDAOFactory.getDAOFactory(
					HNLDAOFactory.HNLDAOFACTORY).getActivityDAO();

			Date now = new Date();

			// test add talent
			Activity act = new Activity();
			act.setActivityType(419);
			act.setTalentID(1);
			act.setDescription("Tel to talent 1");
			act.setIsdelete(false);
			act.setCreateDate(now);
			act.setCreateUser(3);
			act.setModifyDate(now);
			act.setModifyUser(3);
			activityDAO.saveActivity(act);

			act = new Activity();
			act.setActivityType(420);
			act.setTalentID(1);
			act.setDescription("Face to Face for talent 1");
			act.setIsdelete(false);
			act.setCreateDate(now);
			act.setCreateUser(3);
			act.setModifyDate(now);
			act.setModifyUser(3);
			activityDAO.saveActivity(act);

			act = new Activity();
			act.setActivityType(419);
			act.setTalentID(1);
			act.setDescription("Tel to talent 2");
			act.setIsdelete(false);
			act.setCreateDate(now);
			act.setCreateUser(3);
			act.setModifyDate(now);
			act.setModifyUser(3);
			activityDAO.saveActivity(act);

			act = new Activity();
			act.setActivityType(420);
			act.setTalentID(2);
			act.setDescription("Face to Face for talent 2");
			act.setIsdelete(false);
			act.setCreateDate(now);
			act.setCreateUser(3);
			act.setModifyDate(now);
			act.setModifyUser(3);
			activityDAO.saveActivity(act);

		} catch (DAOException e) {
			LOG.error("Error in Getting DAO. ", e);
		}
	}
}
